<%@ page import="com.xinjie.www.util.Constants" %>
<%@ page import="com.xinjie.www.po.User" %>
<%@ page import="com.xinjie.www.service.ban.BanServiceImpl" %>
<%@ page import="com.xinjie.www.po.Ban" %>
<%@ page import="java.util.List" %>
<%@ page import="com.xinjie.www.service.tieba.TiebaServiceImpl" %>
<%@ page import="com.xinjie.www.po.Tieba" %>
<%@ page import="java.sql.SQLException" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>写评论</title>
    <style>
        .input1 {
            border: 1px solid transparent;
            color: transparent;
            outline: 0;
        }
    </style>
</head>
<body>
<%
    String s = request.getParameter("tieba");
    Object o = request.getSession().getAttribute(Constants.USER_SESSION);
    User user = (User) o;
    BanServiceImpl banService = new BanServiceImpl();
    List<Ban> bans = null;
    try {
        bans = banService.getBan();
    } catch (SQLException | ClassNotFoundException e) {
        e.printStackTrace();
    }
    TiebaServiceImpl tiebaService = new TiebaServiceImpl();
    List<Tieba> tiebas = null;
    try {
        tiebas = tiebaService.getAllTieba();
    } catch (SQLException | ClassNotFoundException e) {
        e.printStackTrace();
    }
    Tieba t = new Tieba();
    assert tiebas != null;
    for (Tieba tieba : tiebas) {
        if (tieba.getName().equals(s)) {
            t = tieba;
            break;
        }
    }
    Ban ban1 = null;
    for (Ban ban : bans) {
        if (ban.getUserId() == user.getUserId() && ban.getTiebaId() == t.getTiebaId()) {
            ban1 = ban;
            break;
        }
    }
    if (ban1 != null) {
        request.getSession().setAttribute("BanComment", "你在本贴吧已被封禁不能评论");
        response.sendRedirect("/UserPage/PostList.jsp");
    }
%>
<div align="center">
    <form action="${pageContext.request.contextPath}/comment.do" method="get">
        <label>
            <input type="text" class="input1" name="method" value="write">
        </label>
        <label>
            <input type="text" class="input1" name="tieba" value="${param.tieba}">
        </label>
        <label>
            <input type="text" class="input1" name="postId" value="${param.postId}">
        </label><br>
        评论内容：<label>
        <textarea name="content" cols="20" rows="10"></textarea>
    </label><br>
        <input type="submit" value="发布">
    </form>
    <a href="PostList.jsp?tieba=<%=s%>">返回</a>
</div>
</body>
</html>